<template>
	<view class="container" :style="{'height':contentHeight}">
		<!-- 钱包余额 -->
		<view class="balance">
			<view>钱包余额 （元）</view>
			<view>{{ userInfo.amount/100 }}</view>
			<view v-if="amountFrozen>0">含冻结金额 (元)：{{amountFrozen/100}}
				<image @click="isShowAmountFrozenInfo=true"
					src="https://images.linglinggong.net/static/icon3/popupWatch/hjgkhkl.png" mode="aspectFill"></image>
			</view>
		</view>
		<view class="handle">
			<view @click="handleOpenPage(0)">
				<image src="https://images.linglinggong.net/static/newMy/wallet2.png" mode="aspectFill"></image>
				<text>充值</text>
			</view>
			<view @click="handleOpenPage(1)">
				<image src="https://images.linglinggong.net/static/newMy/wallet1.png" mode="aspectFill"></image>
				<text>提现</text>
			</view>
		</view>
		<view class="function-list">
			<view class="item" v-for="(item,index) in functionList" @click="jumpPage(index)">
				<view v-if="index==1&&!isEnsureAccount" class="tab"> 未缴纳 </view>
				<view v-if="index==2&&!isTixian" class="tab"> 未绑定 </view>
				<image :src="item.icon" mode=""></image>
				<text>{{item.name}}</text>
			</view>
		</view>
		<view class="income">
			<view class="title"> 每日收入 </view>
			<view class="content">
				<view class="money">
					<text>+{{nowDayIncome}}</text>
					<text>今日收入(元)</text>
				</view>
				<view class="calendar">
					<view class="item" v-for="(item,index) in list.slice(0,6)" @click="selectDay(index)">
						<text :style="{'color':index==currentIndex?'#FF851D':'#515151'}">{{item}}</text>
						<view v-if="index==currentIndex" class="dot">
						</view>
					</view>
					<view class="item " @click="selectDay(6)" style="color: #F85A41;"><text>今日</text>
						<view v-if="currentIndex==6" class="dot now">
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'
	import xpPicker from '@/components/xp-picker/xp-picker'
	import unit from '../../libs/newUnit.js'
	import {
		getToExceedTheTime,
		getUserInfo
	} from '../../libs/unit.js'
	export default {
		components: {
			uniLoadMore,
			xpPicker
		},
		data() {
			return {
				hasFlag: true, // 是否还有更多数据要加载
				amount: 5000, //
				userInfo: {
					user: {},
					params: {}
				}, //当前用户信息
				flowList: [], //资金流水
				flowObj: { //(type 0 资金 50 诚信值)
					type: 0,
					findDate: '',
					pageNum: 0,
					pageSize: 10,
				},
				amountFrozen: 0,
				isShowAmountFrozenInfo: false,
				expireTime: '',
				isRecharge: false,
				inAccount: 0,
				outAccount: 0,
				contentHeight: '',
				functionList: [{
					name: '钱包明细',
					icon: 'https://images.linglinggong.net/static/newMy/wallet5.png'
				}, {
					name: '保证金',
					icon: 'https://images.linglinggong.net/static/newMy/wallet4.png'
				}, {
					name: '提现渠道',
					icon: 'https://images.linglinggong.net/static/newMy/wallet3.png'
				}],
				isEnsureAccount: false, // 是否缴纳保证金
				isTixian: false, // 是否绑定提现渠道
				list: [],
				list2: [],
				currentIndex: 6,
				nowDayIncome: 0
			}
		},
		methods: {
			jumpPage(index) {
				if (index == 0) {
					uni.navigateTo({
						url: '/pages/my-wallet/wallet-detail'
					})
				} else if (index == 1) {
					uni.navigateTo({
						url: "/pages/syncAppNewPage/earnest/earnest"
					})
				} else if (index == 2) {
					uni.navigateTo({
						url: '/pages/pay-way/pay-way'
					})
				}
			},
			// 打开内页面
			handleOpenPage(page) {
				if (page == 0) {
					uni.navigateTo({
						url: '/pages/prepaid/prepaid'
					})
					this.isRecharge = !this.isRecharge
					// uni.showToast({
					// 	title: '暂不开放',
					// 	icon: 'none'
					// })
				} else {
					if (this.amountFrozen > 0) {
						uni.navigateTo({
							url: '/pages/cash-out/cash-out?amountFrozen=' + this.amountFrozen
						})
					} else {
						uni.navigateTo({
							url: '/pages/cash-out/cash-out'
						})
					}
				}
			},
			// 刷新
			getAmountFrozen() {
				if (uni.getStorageSync('jf_expireTime')) {
					let jf_expireTime = getToExceedTheTime(uni.getStorageSync('jf_expireTime'))
					if (jf_expireTime < 0) {
						if (uni.getStorageSync('yajinItem')) {
							if (uni.getStorageSync('yajinItem').status == 1) {
								this.amountFrozen = uni.getStorageSync('yajinItem').deposit
								this.expireTime = uni.getStorageSync('yajinItem').expireTime
								let expireT = getToExceedTheTime(this.expireTime)
								if (expireT >= 0) {
									try {
										uni.removeStorageSync('jf_expireTime')
										uni.removeStorageSync('yajinItem')
									} catch (e) {
										// error
									}
									this.amountFrozen = 0
								}
							}
						} else {
							unit.Closure_margin().then(v => {
								// if(v.code){
								// 	return uni.showToast({
								// 		title:v.msg,
								// 		icon:'none'
								// 	})
								// }
								if (v.data != '0') {
									if (v.data.status == 1) {
										this.amountFrozen = v.data.deposit
										this.expireTime = v.data.expireTime
									}
								}
							})
						}
					} else {
						try {
							uni.removeStorageSync('jf_expireTime')
						} catch (e) {
							// error
						}
					}
				}
			},
			async getUser() {
				let res = await this.$fetch(this.$api.get_user_by_token, {}, 'POST')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				this.userInfo = res.data
				this.isEnsureAccount = res.data.ensureAccount > 0
			},
			async query_bind_user_bank() {
				let res = await this.$fetch(this.$api.query_bind_user_bank, {}, 'POST')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				this.isTixian = res.data.length > 0
			},
			getDate(number = 0) {
				let nowdate = new Date();
				nowdate.setTime(nowdate.getTime() + (24 * 3600 * 1000) * number);
				let y = nowdate.getFullYear();
				let m = nowdate.getMonth() + 1;
				let d = nowdate.getDate() < 10 ? '0' + nowdate.getDate() : nowdate.getDate();
				let retrundate = m + '.' + d;
				return retrundate
			},
			getCompleteDate(number = 0) {
				let nowdate = new Date();
				nowdate.setTime(nowdate.getTime() + (24 * 3600 * 1000) * number);
				let y = nowdate.getFullYear();
				let m = nowdate.getMonth() + 1 < 10 ? '0' + (nowdate.getMonth() + 1) : nowdate.getMonth() + 1;
				let d = nowdate.getDate() < 10 ? '0' + nowdate.getDate() : nowdate.getDate();
				let retrundate = y + '-' + m + '-' + d;
				return retrundate
			},
			selectDay(index) {
				this.currentIndex = index
				this.getMyflow()
			},
			async getMyflow() {
				this.nowDayIncome = 0
				let timer = new Date()
				this.flowObj.findDate = this.list2[this.currentIndex].slice(0, 7)
				// let nowDay = timer.getFullYear() + '-' + (timer.getMonth() + 1 < 10 ? '0' + (timer.getMonth() + 1) :
				// 	timer.getMonth() + 1) + '-' + (timer.getDate() < 10 ? '0' + timer.getDate() : timer.getDate())
				let res = await this.$fetch(this.$api.my_flow, this.flowObj, 'POST')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				let newArr = res.rows.filter((item) => {
					return item.createTime.slice(0, 10) == this.list2[this.currentIndex]
				})
				newArr.forEach((ele) => {
					if (ele.amount > 0) {
						this.nowDayIncome += ele.amount / 100
					}
				})
				this.nowDayIncome = this.nowDayIncome.toFixed(2)
			},
		},
		onShareAppMessage() {
			return {
				title: "在家找日结兼职，工种齐全",
				desc: "免费使用，提前在家找日结兼职",
				path: `/pages/start-n/start-n`,
				imageUrl: 'https://images.linglinggong.net/static/employee-share.jpg',
				success: res => {}
			}
		},
		onShow() {
			this.contentHeight = uni.getWindowInfo().windowHeight + "px"
			this.getAmountFrozen()
			for (let i = 0; i < 7; i++) {
				this.list.unshift(this.getDate(`-${i}`))
				this.list2.unshift(this.getCompleteDate(`-${i}`))
			}
			this.getUser()
			this.query_bind_user_bank()
			this.getMyflow()
		},
		onLoad() {},
	}
</script>
<style lang="less">
	.container {
		width: 100%;
		background-color: #FFFFFF;
		overflow: hidden;
		width: 690rpx;
		padding: 0 30rpx;
		margin: 0 auto;

		&>.balance {
			margin: 52rpx auto 0 auto;
			text-align: center;
			background: linear-gradient(#FCC928, #FFBB00);
			padding: 50rpx 0 60rpx;
			border-radius: 24rpx;

			&>view:nth-child(1) {
				color: rgba(64, 33, 16, 0.70);
				margin-bottom: 20rpx;
				height: 40rpx;
			}

			&>view:nth-child(2) {
				font-size: 32px;
				height: 90rpx;
			}

			&>view:nth-child(3) {
				font-size: 28rpx;
				margin-top: 20rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #40200E;
				line-height: 28rpx;
				display: flex;
				justify-content: center;

				&>image {
					width: 29rpx;
					height: 28rpx;
					margin-left: 8rpx;
				}
			}
		}

		.t-box-line {
			width: 100%;
			height: 80rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.t-box-line-box {
				width: 92%;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.t-box-line-left {
					width: 30%;
					margin-left: 10rpx;
					height: 70rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.t-box-line-left-inner {
						font-size: 28rpx;
						position: relative;

						// 
						.t-box-line-left-inner-time {
							position: absolute;
							right: -25%;
							bottom: 6rpx;
							// border: 1px solid;
							display: flex;
							justify-content: center;
							align-items: center;
							// width: 100%;
							// height: 100rpx
						}
					}
				}

				.t-box-line-right {
					flex: 1;
					height: 70rpx;
					display: flex;
					justify-content: flex-end;
					align-items: center;
					margin-right: 10rpx;

					.t-box-line-right-left {
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 26rpx;
						color: #A2A2A2;
					}

					.t-box-line-right-right {
						display: flex;
						justify-content: center;
						align-items: center;
						margin-left: 100rpx;
						font-size: 26rpx;
						color: #A2A2A2;
					}
				}
			}
		}

		&>.handle {
			height: 100rpx;
			display: flex;
			justify-content: space-between;
			margin-top: 20rpx;

			&>view {
				width: 344rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background-color: #F1F1F5;
				border-radius: 12px 0px 0px 12px;
				font-weight: bold;

				image {
					width: 36rpx;
					height: 36rpx;
					margin-right: 10rpx;
				}
			}

			&>view:nth-child(2) {
				border-radius: 0px 12px 12px 0px;
			}
		}

		&>.function-list {
			display: flex;
			justify-content: space-around;
			height: 120rpx;
			margin-top: 54rpx;

			.item {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				align-items: center;

				image {
					width: 76rpx;
					height: 76rpx;
				}
			}

			.item:nth-child(2),
			.item:nth-child(3) {
				position: relative;

				.tab {
					position: absolute;
					top: 0;
					left: 46rpx;
					z-index: 999;
					width: 84rpx;
					height: 28rpx;
					background-color: #F85A41;
					border-radius: 6rpx;
					box-shadow: 0 2rpx 6rpx 2rpx rgba(248, 90, 65, 0.50);
					text-align: center;
					line-height: 28rpx;
					color: #FFFFFF;
					font-size: 20rpx;
				}
			}
		}

		&>.income {
			margin-top: 74rpx;

			&>.title {
				font-weight: bold;
				margin-bottom: 20rpx;
			}

			&>.content {
				height: 320rpx;
				border-radius: 24rpx;
				background-color: #F1F1F5;
				padding: 60rpx 30rpx;
				box-sizing: border-box;

				.money {
					width: 100%;
					text-align: center;
					margin-bottom: 44rpx;
					line-height: 60rpx;

					text:nth-child(1) {
						display: block;
						font-size: 52rpx;
						font-weight: bold;
					}

					text:nth-child(2) {
						display: block;
						color: #515151;
						font-size: 24rpx;
					}
				}

				.calendar {
					display: flex;
					justify-content: space-between;
					font-size: 28rpx;
					font-weight: bold;
					height: 56rpx;
					color: #515151;

					.item {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						align-items: center;

						.dot {
							width: 12rpx;
							height: 12rpx;
							border-radius: 50%;
							background-color: #FF851D;
						}

						.now {
							background-color: #F85A41;
						}
					}
				}
			}
		}

		.modal {
			width: 430rpx;
			height: 270rpx;
			padding: 30rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			&>image {
				width: 160rpx;
				height: 160rpx;
				margin-bottom: 10rpx;
			}
		}
	}

	#blackFontColor {
		color: #000000;
		width: 300rpx;
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.AmountFrozenInfo-mask {
		width: 100vw;
		height: 100vh;
		position: fixed;
		background-color: rgba(0, 0, 0, .6);
		top: 0;
		left: 0;
		z-index: 999;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.AmountFrozenInfo-content {
		width: 630rpx;
		height: 393rpx;
		background: #FFFFFF;
		border-radius: 20rpx;

		&>image {
			width: 34rpx;
			height: 34rpx;
			margin: 20rpx 0 0 20rpx;
		}
	}

	.AmountFrozenInfo-content-text-view {
		// width: 200rpx;
		position: relative;
		left: 50%;
		transform: translateX(-50%);
		display: flex;
		flex-direction: column;
		align-items: center;

		&>text:nth-child(1) {
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #1A1A1A;
			line-height: 56rpx;
		}

		&>text:nth-child(2) {
			font-size: 60rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #1A1A1A;
			line-height: 80rpx;
		}
	}

	.jf-time {
		position: relative;
		left: 50%;
		transform: translateX(-50%);
		top: 40rpx;
		width: 570rpx;
		height: 140rpx;
		background: #F2F2F2;
		border-radius: 12rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.jf-time-title {
		width: 510rpx;
		display: flex;
		justify-content: space-between;
		margin-top: 32rpx;

		&>text:nth-child(1) {
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #1A1A1A;
			line-height: 32rpx;
		}

		&>text:nth-child(2) {
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #1A1A1A;
			line-height: 32rpx;
		}
	}

	.jf-time-timeInfo {
		width: 510rpx;
		margin-top: 24rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FE4B28;
		line-height: 24rpx;
	}
</style>